<admintpl file="header" xmlns="http://www.w3.org/1999/html"/>
</head>
<body>
<div class="wrap">
    <form method="post" class="form-horizontal " id="myform" enctype="multipart/form-data"  action="{:U('Admin/Guest/publish')}">
         <div class="control-group">
            <label class="span1 control-label" style="width: 90px;">竞猜题目</label>
            <div class="span3">
				<input type="text" name="subtitle" value="{$quiz_info.quiz_name}" id="quiz">
            </div>
        </div>

		<div class="control-group">
			<label class="span1 control-label" style="width: 90px;">
				最终正确结果为：（请勾选正确选项）
			</label>
			<div class="span3">
				<foreach name="answer" item="vo">
					<input type="radio" id="answer" name="answer" <?php if($quiz_info['correct_id'] == $vo['rule_id']){echo "checked";}?> value="{$vo.rule_id}">{$vo.rule_name}
				</foreach>
			</div>
		</div>
        
		<input type="hidden" name="id" id="id" value="<?php echo $quiz_id;?>">
		<input type="hidden" name="live_id" id="live_id" value="<?php echo $live_id;?>">
        <div class="form-actions" style="padding-left:260px;">
			<input type="button" class="btn btn-primary" id="ajaxform"value="保存" onclick="save_full()">
            &nbsp;&nbsp;<a class="btn" id="ajaxback">{:L('BACK')}</a>
        </div>
    </form>
</div>
<script src="__PUBLIC__/js/common.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/content_addtop.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript"
        src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.10.0/jquery.validate.min.js"></script>
<script src="__PUBLIC__/js/layer/layer.js"></script>
<script>

	function save_full(){    // 提交按钮触发事件
		var tourl  = $("#myform").attr("action");    // 获取 表单的 提交地址
		var answer = $("input[name='answer']:checked").val();
		var id     = $("#id").val();
		var live_id = $("#live_id").val();

		$.post(tourl,{answer:answer,id:id,live_id:live_id},function(result){
        	if(result == '1'){
        		var msg = '设置成功';
        	}else{
        		var msg = '设置失败';
        	}

    		parent.layer.msg(msg,{time:2000},1,function(a){

    		});
    		setTimeout(function(){
    			var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    			parent.layer.close(index);
    		}, 1000);
		return true;
		});
	}

$(function(){
	$("[name='administrator_checbox']").click(function(){
		var administrator_id = $(this).val();
		var administrator_name = $(this).attr('administrator_name');
		
		var administrator_hidden_ids = $("#administrator_hidden_ids").val();
		var administrator_values = $("#administrator").val();
		
		var ids_arr = administrator_hidden_ids.split(",");         
		var values_arr = administrator_values.split(",");   
		
		if(ids_arr.indexOf(administrator_id) == '-1'){
			administrator_hidden_ids+=administrator_id+',';
			administrator_values+=administrator_name+',';
			$("#administrator").val(administrator_values);
			$("#administrator_hidden_ids").val(administrator_hidden_ids);
		}else{
			$.each(ids_arr,function(index,item){
				 if(item==administrator_id){
					 ids_arr.splice(index,1);
					 values_arr.splice(index,1);
				 }
			}) 
			administrator_hidden_ids = ids_arr.join(",");
			administrator_values = values_arr.join(",");
			$("#administrator").val(administrator_values);
			$("#administrator_hidden_ids").val(administrator_hidden_ids);
		}
	})
})
	function html5Reader(file, previewId){
		var file = file.files[0];
		var reader = new FileReader();
		reader.readAsDataURL(file);
		reader.onload = function(e){
			$('#'+previewId).attr('src', this.result);
		}
	}
	function image_change(fileId, previewId) {
		var pic = document.getElementById(previewId),
				file = document.getElementById(fileId);

		var ext = file.value.substring(file.value.lastIndexOf(".")+1).toLowerCase();

		// gif在IE浏览器暂时无法显示
		if(ext != 'png' && ext != 'jpg' && ext != 'jpeg'){
			alert("图片的格式必须为png或者jpg或者jpeg格式！");
			return;
		}
		var isIE = navigator.userAgent.match(/MSIE/)!= null,
				isIE6 = navigator.userAgent.match(/MSIE 6.0/)!= null;

		if(isIE) {
			file.select();
			var realLocalPath = document.selection.createRange().text;

			// IE6浏览器设置img的src为本地路径可以直接显示图片
			if (isIE6) {
				pic.src = realLocalPath;
			}else {
				// 非IE6版本的IE由于安全问题直接设置img的src无法显示本地图片，但是可以通过滤镜来实现
				pic.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='image',src=\"" + realLocalPath + "\")";
				// 设置img的src为base64编码的透明图片 取消显示浏览器默认图片
				pic.src = '';
			}
		}else {
			html5Reader(file, previewId);
		}
	}

	$("#picker").click(function(){
		$("#imageFile").click();
	});

	$("#imageFile").change(function(){
		image_change('imageFile', 'imagePreview');
	});
// ajax 提交表单
$(document).ready(function(){

    $("#ajaxback").click(function(){
    	var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
		parent.layer.close(index);
    });
});
</script>
</body>
</html>